package com.gitee.xmhzzz.component.web;

import com.gitee.xmhzzz.component.web.config.XmhWebProperties;
import com.gitee.xmhzzz.component.web.exception.GlobalExceptionHandler;
import com.gitee.xmhzzz.component.web.intercepter.AccessLogInterceptor;
import com.gitee.xmhzzz.component.web.intercepter.RequestResponseInterceptor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;

import javax.servlet.Filter;

/**
  * @ClassName
  * @Description
  * @Author wzq
  * @Date 2023/12/18 10:20
  * @Version 1.0
  */
@Configuration
@Import({XmhWebMvcConfigurer.class, RequestResponseInterceptor.class, AccessLogInterceptor.class})
@EnableConfigurationProperties({XmhWebProperties.class})
public class WebAutoConfiguration {
    @Bean
    public GlobalExceptionHandler globalExceptionHandler() {
        return new GlobalExceptionHandler();
    }

    @Bean
    public FilterRegistrationBean registLogFilter(RequestResponseInterceptor requestResponseInterceptor) {
        FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
        bean.setFilter(requestResponseInterceptor);
        //级别在sleuth过滤器后
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE + 6);
        return bean;
    }

}
